<template>
  <div class="wrapper-container1">
    <el-row>
      <el-col :span="11">
        <div
          class="wrapper-container"
          style="display: flex; flex-direction: column;width:100%"
        >
          <div class="search-container">
            <div class="search-container-left">
              <div
                class="search-container-item"
                v-for="(select, index) in selectList"
                :key="index"
              >
                <div v-if="select.type === 'selectTree'" class="box">
                  <span v-show="select.name">{{ select.name }}</span>
                  <el-popover
                    trigger="click"
                    placement="bottom"
                    v-model="showUnitTree"
                    style="cursor: pointer;"
                    width="120">
                    <div style="max-height: 260px;overflow-y: auto;">
                    <el-tree
                          default-expand-all
                          node-key="id"
                          :data="select.valList"
                          :expand-on-click-node="false"
                          :props="props"
                          @node-click="toShowUnitInfo">
                    </el-tree>
                    </div>
                    <el-input slot="reference" v-model="select.val" class="selectTree"
                        clearable :readonly="true" style="width: 120px;" suffix-icon="el-icon-arrow-down">
                    </el-input>
                  </el-popover>
                </div>
                <div v-if="select.type === 'select'" class="box">
                  <span v-show="select.name">{{ select.name }}</span>

                  <el-select
                    v-model="select.val"
                    size="mini"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in select.valList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </div>
                <div class="box" v-if="select.type === 'data'">
                  <span class="demonstration" v-show="select.name">{{
                    select.name
                  }}</span>
                  <el-date-picker
                    v-model="select.val"
                    type="date"
                    placeholder="选择日期"
                    prefix-icon="aaa"
                  >
                  </el-date-picker>
                </div>
                <div v-if="select.type === 'MultiSelect'" class="box"></div>
                <div v-if="select.type === 'btn'" class="box">
                  <span class="demonstration" v-show="select.name">{{
                    select.name
                  }}</span>
                  <el-input
                    v-model="select.val"
                    placeholder="请输入内容" style="width: 150px;"
                  ></el-input>
                </div>
              </div>

              <div class="search-button" @click="queryPlaceInfo">
                <img src="../../../../assets/assessment/icon-search.png" alt="" />
                <span @click="queryPlaceInfo">查询</span>
              </div>
            </div>
          </div>

          <div class="assessment-container">
            <div class="table-container">
              <el-table
                :data="tableData"
                border
                class="xpaas-table-class"
                row-class-name="xpaas-row-class"
                cell-class-name="xpaas-cell-class"
                header-row-class-name="xpaas-header-row-class"
                header-cell-class-name="xpaas-header-cell-class"
                style="height: 580px; overflow-y: auto"
                @selection-change="handleSelectionChange"
              >
                <el-table-column :label="kxbgTitle" align="center">
                  <el-table-column align="center" type="selection" width="80">
                  </el-table-column>
                  <el-table-column
                    prop="kcbh"
                    label="课程编号"
                    align="center"
                    width="160"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="kcmc"
                    label="选修课课程名称"
                    align="center"
                  >
                  </el-table-column>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="2">
        <div class="arrow-right-postion">
          <div class="btn" @click="transferData">
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </el-col>
      <el-col :span="11">
        <div
          class="wrapper-container"
          style="display: flex; flex-direction: column;width:100%"
        >
          <div class="search-container">
            <div class="search-container-left">
              <div
                class="search-container-item"
                v-for="(select, index) in selectList2"
                :key="index"
              >
                <div v-if="select.type === 'select'" class="box">
                  <span v-show="select.name">{{ select.name }}</span>

                  <el-select
                    v-model="select.val"
                    size="mini"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in select.valList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </div>
                <div class="box" v-if="select.type === 'data'">
                  <span class="demonstration" v-show="select.name">{{
                    select.name
                  }}</span>
                  <el-date-picker
                    v-model="select.val"
                    type="date"
                    placeholder="选择日期"
                    prefix-icon="aaa"
                  >
                  </el-date-picker>
                </div>
                <div v-if="select.type === 'MultiSelect'" class="box"></div>
                <div v-if="select.type === 'btn'" class="box">
                  <span class="demonstration" v-show="select.name">{{
                    select.name
                  }}</span>
                  <el-input
                    v-model="select.val"
                    placeholder="请输入内容"
                  ></el-input>
                </div>
              </div>
            </div>
          </div>

          <div class="assessment-container">
            <div class="table-container">
              <el-table
                :data="tableData2"
                border
                class="xpaas-table-class"
                row-class-name="xpaas-row-class"
                cell-class-name="xpaas-cell-class"
                header-row-class-name="xpaas-header-row-class"
                header-cell-class-name="xpaas-header-cell-class"
                style="height: 580px; overflow-y: auto"
              >
                <el-table-column align="center" :render-header="renderHeader">
                  <el-table-column
                    prop="kcbh"
                    label="课程编号"
                    width="160"
                    align="center"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="kcmc"
                    label="选修课课程名称"
                    align="center"
                  >
                  </el-table-column>
                  <el-table-column label="操作" align="center" width="160">
                    <template slot-scope="scope">
                      <div
                        style="
                          display: flex;
                          padding-left: 10px;
                          justify-content: space-around;
                        "
                      >
                      <div class="button-style" style="border-color: #F05943; background-color: #FFEEF3; margin-right: 15px;" @click="deleteRow(scope.row,scope.$index)">
                        <i class="el-icon-delete" style="color: #F05943; margin-right: 5px;" />
                        <span style="color: #F05943;">删除</span>
                      </div>
                      </div>
                    </template>
                  </el-table-column>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div class="btn-caozuo">
      <div class="button-style" style="border-color: #F3B815; background-color: #FFF6EF; margin-right: 15px;" @click="nextStep">
        <span style="color: #F3B815;">下一步</span>
      </div>
      <div class="button-style" style="border-color: #F05943; background-color: #FFEEF3; margin-right: 15px;" @click="cancelStep">
        <span style="color: #F05943;">取&emsp;消</span>
      </div>
    </div>
  </div>
</template>

<script>
import {xxkkkgl_course_list, queryCommonXueqi, queryCommonDept} from "@/api/trainingManagement/place.js";

import ButtonItem from "@/components/ButtonItem.vue";

export default {
  components: {
    ButtonItem,
  },
  name: "supervisonMain",
  data() {
    return {
      props:{
        children: "children",
        label: "name",
      },
      unitId: "",
      showUnitTree: false,
      kxbgTitle: "可选的课程列表（50个）",
      yxbgTitle: '',
      selectList: [
        {
          type: "selectTree",
          name: "承担单位：",
          val: "",
        },
        {
          type: "btn",
          name: "选修课课程名称：",
          val: "",
        },
      ],
      selectList2: [
        {
          type: "select",
          name: "开课学期：",
          val: "",
          valList: [],
        },
      ],
      tableData: [],
      tableData2: [],
      // 选择列表数据
      multipleSelection: [],
      selectTotle: 14, //选择个数
    };
  },
  mounted() {
    this.queryPlaceInfo();
    this.queryCommonXueqi();
    this.queryCommonDept();
  },
  methods: {
    // 获取部门
    async queryCommonDept() {
      const res = await queryCommonDept();
      if (res.data.code == 200) {
        this.selectList[0].valList = res.data.data;
      }
    },
    toShowUnitInfo(data) {
      this.selectList[0].val = data.name;
      this.unitId = data.id;
      this.showUnitTree = false;
      },
    // 取消
    cancelStep() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.push("/admin/elective/startClassManagement");
    },
     // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.selectList2[0].valList = res.data.data;
        this.selectList2[0].val = this.selectList2[0].valList[0].id;
      }
    },
    nextStep() {
      var list = [];
      if (this.tableData2.length > 0) {
         this.tableData2.forEach(item => {
           let par = {
              "kcbh": item.kcbh,
              "xueqi": this.selectList2[0].val
          }
          list.push(par);
         })
         this.$router.push({
          path: "/admin/elective/generateElectiveCourses",
          query: {
            list: list
          }
        })
      } else {
        this.$message.warning("请先选择课程！");
        return;
      }
    },
    async queryPlaceInfo() {
      const res = await xxkkkgl_course_list();
      if (res.data.code == 200) {
        this.tableData = res.data.data;
        this.kxbgTitle = "可选的课程列表（" + this.tableData.length + "个）"
        this.yxbgTitle = "已选的课程列表（" + this.tableData2.length + "个）"
      }
    },
    renderHeader (h) {
      return (
        <div style="height:30px">
          <span>已选的课程列表</span>
          <el-button
            icon="el-icon-delete"
            class="basic-button red-button"
            style="padding: 7px 10px;position: absolute;right: 50px;color: #ff3819;border: 1px solid #ff3819;background: #ffefef;border-radius: 8px;"
            onClick={()=>this.deletedAll()}
          >全部删除</el-button></div>
      )
    },
    // 选择列表信息全部删除
    deletedAll() {
      this.tableData2.forEach(item => {
        this.tableData.push(item);
      });
      this.tableData2 = [];
      this.selectTotle = 0;
      this.kxbgTitle = "可选的课程列表（" + this.tableData.length + "个）"
    },
    // 删除行信息
    deleteRow(row, index) {
      this.tableData.push(row);
      this.tableData2.splice(index, 1);
      this.selectTotle = this.tableData2.length;
      this.kxbgTitle = "可选的课程列表（" + this.tableData.length + "个）"
    },
    // 表格选择事件
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    transferData() {
      console.log(this.multipleSelection, "this.multipleSelection===")
      for(var i = 0; i< this.tableData.length; i++) {
        var isFlag = false;
        for (var j=0;j <this.multipleSelection.length; j++) {
          if(this.tableData[i].kcbh === this.multipleSelection[j].kcbh) {
            isFlag = true;
            break;
          }
        }
        if(isFlag) {
          this.tableData.splice(i, 1);
          i--;
        }
      }
      this.multipleSelection.forEach(item => {
        this.tableData2.push(item);
      })
      this.selectTotle = this.tableData2.length;
      this.kxbgTitle = "可选的课程列表（" + this.tableData.length + "个）"
      this.yxbgTitle = "已选的课程列表（" + this.tableData2.length + "个）"
    }
  }
};
</script>

<style lang="less" scoped>
@import "../../../../styles/text.less";

/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

// .wrapper-container {
//   width: 100% !important;
//   margin: 0 auto;
// }

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  flex-wrap: wrap;
  .search-container-item {
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
      /deep/ .el-input__inner {
        height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.assessment-container {
  width: 100% !important;
}

.assessment-container .table-container {
  width: 100%;
}

.arrow-right-postion {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 500px;
}

.arrow-right-postion .btn {
  width: 60px;
  height: 60px;
  background: #004ca7;
  border-radius: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.arrow-right-postion .btn > i {
  font-size: 30px;
  font-weight: bold;
  color: #fff;
}
.wrapper-container1 {
  width: calc(100% - 20px);
  margin: 0 auto;
}

.btn-caozuo {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 800px;
  margin: 0 auto;
  padding-top: 50px;
}
// .assessment-container {
//   width: calc(100% - 20px);
//   .table-container {
//      width: 100%;
//   }
// }
/deep/ .el-tree-node {
  color: #004ca7;
}
@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
  border: 1px solid #004ca7;
  border-radius: 9px;
  ::v-deep div.el-table__header-wrapper {
    table.el-table__header {
      thead {
        tr.xpaas-header-row-class {
          padding: 0;
          height: 60px;
          background-color: #edf2f9;
          font-size: 16px;
          font-family: @fontFamily;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          th.xpaas-header-cell-class {
            font-weight: bold;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
  ::v-deep div.el-table__body-wrapper {
    table.el-table__body {
      tbody {
        tr.xpaas-row-class {
          td.xpaas-header-cell-class {
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
          td.xpaas-cell-class {
            height: 60px;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            div.cell {
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
}
.button-style {
  float: left;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  width: auto;
  height: 28px;
  line-height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-wrap: nowrap;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  box-sizing: border-box;
  > img {
    width: 16px;
    height: 16px;
    margin-right: 5px;
  }
  > span {
    font-size: 14px;
    color: #51aef6;
  }
}
</style>
